package com.wuliang.generate.bean.entities.author;

import com.google.gson.annotations.Expose;
import com.wuliang.generate.common.core.basic.BasicEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.context.annotation.Lazy;

import javax.persistence.*;
import java.util.Set;

/**
 * @author 邬魉
 */
@Data
@Lazy
@Entity
@Builder
@Cacheable
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("认证用户")
@EqualsAndHashCode(callSuper = true)
@Table(name = "t_author_user", schema = "wuliang_generate_author")
public class AuthorUser extends BasicEntity {

    @Expose
    @Column(name = "user_username", columnDefinition = "varchar(255) not null comment '登录账号'")
    @ApiModelProperty(name = "userUsername", value = "登录账号")
    String userUsername;

    @Expose(serialize = false, deserialize = false)
    @Column(name = "user_password", columnDefinition = "varchar(255) not null comment '登录密码'")
    @ApiModelProperty(name = "userPassword", value = "登录密码")
    String userPassword;

    @Expose
    @Column(name = "user_telephone", columnDefinition = "varchar(255) not null comment '用户手机号'")
    @ApiModelProperty(name = "userTelephone", value = "用户手机号")
    String userTelephone;

    @Expose
    @Column(name = "user_openid", columnDefinition = "varchar(255) null comment '微信用户唯一性标识'")
    @ApiModelProperty(name = "userOpenid", value = "微信用户唯一性标识")
    String userOpenid;

    @Expose
    @Column(name = "user_nick", columnDefinition = "varchar(255) null comment '用户昵称'")
    @ApiModelProperty(name = "userNick", value = "用户昵称")
    String userNick;

    @OneToOne
    @JoinColumn(name = "id", referencedColumnName = "user_id")
    private AuthorUserInfo userInfo;

    @OneToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "c_user_permission", joinColumns = {
            @JoinColumn(name = "user_id", referencedColumnName = "id")
    }, inverseJoinColumns = {
            @JoinColumn(name = "permission_id", referencedColumnName = "id")
    })
    private Set<AuthorPermission> permissions;
}
